﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Entity;
using Utility;

namespace StudentAppointmentPlatform
{
    public partial class ShowServices : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            string loginType = Session["LoginType"] as string;
            if (string.IsNullOrWhiteSpace(loginType))
            {
                Alert.AlertOnPage(Page, "您可能未登录，或系统出错，即将跳转到默认页面。");
                Redirect.Js_Redirect(Page, "/Default.aspx");
            }

            string userId = Session["UserId"].ToString();

            AppointmentService[] services = new AppointmentService[] { };
            if (loginType == "Student")
            {
                services = ServiceBO.GetServicesForStudent();
            }
            else if (loginType == "Director")
            {
                services = ServiceBO.GetServicesForDirector(userId);
            }

            foreach (AppointmentService service in services)
            {
                // ServiceItem item = new ServiceItem();
                // 在运行时通常不适用new关键字创建UserControl对象，而是以动态加载.ascx文件的形式创建:
                ServiceItem serviceItem = (ServiceItem)LoadControl("ServiceItem.ascx");
                serviceItem.Service = service;
                serviceItem.SetInfo();

                upServices.ContentTemplateContainer.Controls.Add(serviceItem);
            }
        }
    }
}